//GPS管理器
function CallbackEventManager(oEventCaller){
	this.eventHandles=[];
	this.iPointRef=1;
	this.eventCaller=oEventCaller;
	
	this.addHandle=function(oFunc){
		this.iPointRef++;
		this.eventHandles[this.iPointRef]=oFunc;
		return this.iPointRef;
	}
	this.RemoveHandle=function(iPoint){
		this.eventHandles[tiPoint]=false;
		delete this.eventHandles[tiPoint];
	}
	
	this.PositionEvent=function(fSuccess,eventInfo){
		var needDleteHandles=[];
		for(var i in this.eventHandles){
			var flag_del=this.eventHandles[i].call(null,fSuccess,eventInfo);
			if(flag_del)needDleteHandles.push(i);
		}
		for(var i in needDleteHandles){
			this.RemoveHandle(needDleteHandles[i]);
		}
	}
	
	this.RegisteHandle=function(oFunc,bDel){
		return this.addHandle(function( oFunction,bDelAfterRutrn){
			var oFuncti=oFunction;
			var bDelete=bDelAfterRutrn;
			return(function(fSuccess,eventInfo){
				oFuncti(fSuccess,eventInfo);
				return bDelete;
			});
		}(oFunc,bDel));
	}
	
	this.getCurrentPosition=function(oFunc,bDel){
		var id=this.RegisteHandle(oFunc,bDel);
		this.eventCaller('getPositionSucceed', 'getPositionFailed');
		return id;
	}
	
	this.getResponseFunc=function(oM,bSuc){
		var oManger=oM;
		var bSuces=bSuc;
		return (function (eventInfo){
			oManger.PositionEvent(bSuces,eventInfo);
		});
	}
	
	//add event for glbal
	window.getPositionSucceed=this.getResponseFunc(this,true);
	/*
	function(position){
		this.PositionEvent(true,position);
	}
	*/
	window.getPositionFailed=this.getResponseFunc(this,false);
	/*
	function(errMsg){
		this.PositionEvent(false,errMsg);
	}
	*/
}